package com.koc.robot;

public class MenuButton 
{
	private float x;
	private float y;
	private String text;
	private ButtonDelegate delegate = null;
	//private float value; TODO: figure out how to use value on Android platform
	private boolean active;
	private boolean hidden;
	
	private float xmargin;
	private float textyplus;
	
	private float height;
	private float width;
	
	public MenuButton(float x, float y, String text)
	{
		this.x = x;
		this.y = y;
		this.text = text;
		this.active = true;
		this.hidden = false;
		
		this.xmargin = 20;
		this.textyplus = -5;
		
		this.height = Global.menufont.getHeight();
		this.width = Global.menufont.getWidth(this.text) - 3.0f;
	}
	
	public void setActive(boolean active)
	{
		this.active = active;
	}
	
	public void update(float dt)
	{
		// TODO: update logic
		
	}
	
	public void render()
	{
		//Color rainbowColor = Global.getrainbowcolor((Global.rainbowi + 0.5f) % 1, 1.0f);
		float r = 190.0f / 255.0f, g = 206.0f / 255.0f, b = 248.0f / 255.0f;
		GraphicsHelper.setFont(Global.menufont);
		
		//TODO: fade color
		GraphicsHelper.setColor(r, g, b, 1.0f);
		GraphicsHelper.print(this.text, this.x - this.width / 2, this.y - this.height / 2 + this.textyplus);
	}
	
	public void setButtonDelegate(ButtonDelegate delegate)
	{
		this.delegate = delegate;
	}
	
	public void mousepressed(float x, float y)
	{
		if (this.active)
		{
			if (this.gethighlight(x, y))
			{
				if (this.delegate != null)
				{
					this.delegate.func();
				}
			}
		}
	}
	
	public boolean gethighlight(float x, float y)
	{
		if ((x >= this.x - this.width / 2 - this.xmargin - 10) && (x < this.x + this.width / 2 + this.xmargin + 10)
		&& (y >= this.y - this.height / 2 - 10) && (y < this.y + this.height / 2 + 10))
		{
			return true;
		}
		
		return false;
	}
}
